<?php 
namespace app\admin\controller;
use think\Controller;

class Member extends Controller{
	public function index(){
		$res = db('member_level')->select();
		$this->assign([
			'res'	=>$res,
		]);
		return view();
	}

	public function add(){
		if(request()->isPost()){
			$data = input('post.');
			$res = db('member_level')->insert($data);
			if($res){
				$this->success('添加会员等级成功！',url('admin/Member/index'));
			}else{
				$this->error('添加会员等级失败！');
			}
		}
		return view();
	}

	public function edit($id){
		if(request()->isPOst()){
			$data = input('post.');
			$dataRes = db('member_level')->update($data);
			if($dataRes){
				$this->success('修改会员等级成功！',url('admin/Member/index'));
			}else{
				$this->error('修改会员等级失败！');
			}
		}
		$res = db('member_level')->find($id);
		$this->assign([
			'res'	=>$res,
		]);
		return view();
	}

	public function del($id){
		$res = db('member_level')->delete($id);
		if($res){
			$this->success('删除会员等级成功！',url('admin/Member/index'));
		}else{
			$this->error('删除会员等级失败！');
		}
	}
}